package com.ltf.order.aspect;

import com.ltf.order.annotation.Greeting;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

/**
 * @Auther: liutf
 * @Date: 2025/4/1
 * @Description: com.ltf.order.aspect
 * @version: 1.0
 */

@Component
@Aspect
@Slf4j
public class GreetingAspect {

    /*
     * 这是一个切入点
     * */
    @Pointcut("@annotation(com.ltf.order.annotation.Greeting)")
    public void cutMethod(){

    }
    /**
     * 切点之前
     */
    @Before("cutMethod()")
    public void before(JoinPoint joinPoint) throws Throwable {
        log.info("============ before ==========");
    }

    /**
     * 切点之后
     */
    @After("cutMethod()")
    public void after() throws Throwable {
        log.info("============ after ==========");
    }

    /**
     * 切点返回内容后
     */
    @AfterReturning("cutMethod()")
    public void afterReturning() throws Throwable {
        log.info("============ afterReturning ==========");
    }

    /**
     * 切点抛出异常后
     */
    @AfterThrowing("cutMethod()")
    public void afterThrowing() throws Throwable {
        log.info("============ afterThrowing ==========");
    }


    @Around("cutMethod() && @annotation(greeting)")
    public Object around(ProceedingJoinPoint point, Greeting greeting) throws Throwable {

        log.info("============ around1 ==========");
        Object  obj= point.proceed(point.getArgs());
        log.info("============ around2 ==========");
        return obj;
    }
}
